
import javax.swing.SwingWorker;
import javax.swing.JTextArea;
import sun.security.x509.AlgIdDSA;

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 *
 * @author jy
 */
public class NLPUI extends javax.swing.JFrame {

    /**
     * Creates new form NLPUI
     */
    public NLPUI() {
        initComponents();
        setLocationRelativeTo(null);
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jPanel1 = new javax.swing.JPanel();
        jScrollPane1 = new javax.swing.JScrollPane();
        Input = new javax.swing.JTextArea();
        jScrollPane2 = new javax.swing.JScrollPane();
        Output = new javax.swing.JTextArea();
        method = new javax.swing.JLabel();
        selectAlgorithm = new javax.swing.JComboBox();
        selectLabel = new javax.swing.JLabel();
        showAlogrithmLabel = new javax.swing.JLabel();
        showTimeLabel = new javax.swing.JLabel();
        jcbCiXing = new javax.swing.JCheckBox();
        usingTime = new javax.swing.JLabel();
        jbtStart = new javax.swing.JButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        setTitle("自然语言处理");
        setLocationByPlatform(true);
        setResizable(false);

        jPanel1.setCursor(new java.awt.Cursor(java.awt.Cursor.DEFAULT_CURSOR));
        jPanel1.setFont(new java.awt.Font("微软雅黑", 0, 14)); // NOI18N

        Input.setColumns(20);
        Input.setLineWrap(true);
        Input.setRows(5);
        Input.setWrapStyleWord(true);
        Input.setCursor(new java.awt.Cursor(java.awt.Cursor.TEXT_CURSOR));
        jScrollPane1.setViewportView(Input);

        Output.setEditable(false);
        Output.setColumns(20);
        Output.setLineWrap(true);
        Output.setRows(5);
        Output.setWrapStyleWord(true);
        jScrollPane2.setViewportView(Output);

        method.setFont(new java.awt.Font("微软雅黑", 0, 14)); // NOI18N
        method.setForeground(new java.awt.Color(204, 0, 0));

        selectAlgorithm.setFont(new java.awt.Font("微软雅黑", 0, 14)); // NOI18N
        selectAlgorithm.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "正向最大匹配", "逆向最大匹配", "概率最大化" }));
        selectAlgorithm.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                selectAlgorithmActionPerformed(evt);
            }
        });

        selectLabel.setFont(new java.awt.Font("微软雅黑", 0, 14)); // NOI18N
        selectLabel.setText("选择分词算法：");

        showAlogrithmLabel.setFont(new java.awt.Font("微软雅黑", 0, 14)); // NOI18N
        showAlogrithmLabel.setText("当前算法：");

        showTimeLabel.setFont(new java.awt.Font("微软雅黑", 0, 14)); // NOI18N
        showTimeLabel.setText("用时：");

        jcbCiXing.setFont(new java.awt.Font("微软雅黑", 0, 14)); // NOI18N
        jcbCiXing.setText("标记词性");
        jcbCiXing.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jcbCiXingActionPerformed(evt);
            }
        });

        usingTime.setFont(new java.awt.Font("微软雅黑", 0, 14)); // NOI18N
        usingTime.setForeground(new java.awt.Color(204, 0, 0));

        jbtStart.setFont(new java.awt.Font("微软雅黑", 0, 14)); // NOI18N
        jbtStart.setText("开始分词");
        jbtStart.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jbtStartActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jScrollPane2, javax.swing.GroupLayout.Alignment.TRAILING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addComponent(showAlogrithmLabel, javax.swing.GroupLayout.PREFERRED_SIZE, 70, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(method, javax.swing.GroupLayout.PREFERRED_SIZE, 177, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(showTimeLabel, javax.swing.GroupLayout.PREFERRED_SIZE, 50, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(usingTime, javax.swing.GroupLayout.PREFERRED_SIZE, 104, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addComponent(selectLabel, javax.swing.GroupLayout.PREFERRED_SIZE, 112, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(selectAlgorithm, javax.swing.GroupLayout.PREFERRED_SIZE, 144, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jcbCiXing)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 36, Short.MAX_VALUE)
                        .addComponent(jbtStart)
                        .addGap(20, 20, 20))))
            .addComponent(jScrollPane1)
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addGap(11, 11, 11)
                .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 186, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(18, 18, 18)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(selectLabel, javax.swing.GroupLayout.PREFERRED_SIZE, 30, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addComponent(selectAlgorithm)
                        .addComponent(jcbCiXing))
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addComponent(jbtStart, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addGap(2, 2, 2)))
                .addGap(27, 27, 27)
                .addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, 174, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(usingTime, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 25, Short.MAX_VALUE)
                    .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(showTimeLabel)
                        .addComponent(showAlogrithmLabel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addComponent(method, javax.swing.GroupLayout.PREFERRED_SIZE, 20, javax.swing.GroupLayout.PREFERRED_SIZE))))
        );

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addContainerGap())
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void selectAlgorithmActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_selectAlgorithmActionPerformed
        
    }//GEN-LAST:event_selectAlgorithmActionPerformed

    private void jcbCiXingActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jcbCiXingActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_jcbCiXingActionPerformed

    private void jbtStartActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jbtStartActionPerformed
        // TODO add your handling code here:
        int algIndex = selectAlgorithm.getSelectedIndex();
        ExcuteInSwingWorker excute = new ExcuteInSwingWorker(Input.getText(), Output, algIndex);
        excute.execute();
        switch(algIndex)
        {
            case 0: method.setText("正向最大匹配");
                break;
            case 1: method.setText("逆向最大匹配");
                break;
            case 2: method.setText("概率最大化分词");
                break;
        }
        while(!excute.isDone());
        showTimeLabel.setText(excute.getUsedTime()+" 毫秒");
        
    }//GEN-LAST:event_jbtStartActionPerformed

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        /*
         * Set the Nimbus look and feel
         */
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /*
         * If Nimbus (introduced in Java SE 6) is not available, stay with the
         * default look and feel. For details see
         * http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html
         */
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException ex) {
            java.util.logging.Logger.getLogger(NLPUI.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(NLPUI.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(NLPUI.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(NLPUI.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        //</editor-fold>

        /*
         * Create and display the form
         */
        java.awt.EventQueue.invokeLater(new Runnable() {

            public void run() {
                new NLPUI().setVisible(true);
            }
        });
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JTextArea Input;
    private javax.swing.JTextArea Output;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JScrollPane jScrollPane2;
    private javax.swing.JButton jbtStart;
    private javax.swing.JCheckBox jcbCiXing;
    private javax.swing.JLabel method;
    private javax.swing.JComboBox selectAlgorithm;
    private javax.swing.JLabel selectLabel;
    private javax.swing.JLabel showAlogrithmLabel;
    private javax.swing.JLabel showTimeLabel;
    private javax.swing.JLabel usingTime;
    // End of variables declaration//GEN-END:variables
}
